package com.itheima;

import java.math.BigDecimal;
import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Objects;

import static java.lang.Math.*;

public class Demo1 {
    public static void main(String[] args) {
        //Math
        /*int abs = Math.abs(-10);
        double ceil = Math.ceil(21.6);
        double floor = Math.floor(12.5);
        long round = Math.round(13.14);
        int max = max(5, 8);
        int min = min(12, -7);
        double pow = pow(2, 4);
        double sqrt = sqrt(121);
        double random = random();
        System.out.println(abs);
        System.out.println(ceil);
        System.out.println(floor);
        System.out.println(round);
        System.out.println(max);
        System.out.println(min);
        System.out.println(pow);
        System.out.println(sqrt);
        System.out.println(random);
*/
        //System
        /*long currentTimeMillis = System.currentTimeMillis();
        System.out.println(currentTimeMillis);
        System.exit(0);*/
        //Object
       /* Student stu1 = new Student("葛小伦",22);
        Student stu2 = new Student("葛小伦",22);
        System.out.println(stu1);
        boolean equals = stu1.equals(stu2);
        System.out.println(equals);*/
        //Objects
        /*Student a1 = new Student("关羽","云长");
        Student a2 = new Student("张飞","翼德");
        Student a3 = new Student("赵云","子龙");
        Student a4 = new Student("马超","孟起");
        Student a5 = new Student("黄忠","汉升");
        String s1 = Objects.toString(a1);
        System.out.println(a1);
        System.out.println(s1);
        System.out.println("----------------");
        String s2 = Objects.toString(a2, "sss");
        System.out.println(s2);
        a2=null;
        System.out.println(Objects.toString(a2, "sss"));
        System.out.println("----------------");
        boolean s3 = Objects.isNull(a3);
        System.out.println(s3);
        a3=null;
        System.out.println(Objects.isNull(a3));
        System.out.println("---------------");
        System.out.println(Objects.nonNull(a4));
          a4=null;
        System.out.println(Objects.nonNull(a4));*/
        //BigDecimal
        /*BigDecimal b1 = new BigDecimal("12");
        BigDecimal b2 = new BigDecimal("-12.3");
        BigDecimal add = b1.add(b2);
        System.out.println("和为："+add);
        System.out.println(b1.subtract(b2));
        //System.out.println(b1.divide(b2));
        System.out.println(b1.multiply(b2));
        System.out.println(b1.divide(b2, 5, BigDecimal.ROUND_UP));
        System.out.println(b1.divide(b2, 2, BigDecimal.ROUND_FLOOR));
        System.out.println(b1.divide(b2, 5, BigDecimal.ROUND_HALF_UP));*/
        //Integer
        /*System.out.println(Integer.valueOf(12) + 12);
        System.out.println(Integer.valueOf("12") + 12);
        //自动拆箱和自动装箱（理解）
        Integer i = 100;
        i+= 200;var
        System.out.println(i);
        //int和String类型的相互转换
        int a = 10;
        System.out.println(String.valueOf(a) + a);
        String b = "13";
        System.out.println(Integer.parseInt(b) + 14);
        System.out.println(Integer.valueOf(b) + 14);//自动装箱，自动拆箱
        //字符串数据排序案例（应用）
        String s = "91 27 36 38 50";
       String[] str = s.split(" ");
       int[] arr = new int[str.length];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(str[i]);
        }
       Arrays.sort(arr);
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(String.valueOf(arr[i]+" "));
//        }
        System.out.println(Arrays.toString(arr));*/
        //递归
        /*//- 递归的注意事项
        //  - 递归一定要有出口。否则内存溢出
        //  - 递归虽然有出口，但是递归的次数也不宜过多。否则内存溢出
        System.out.println(getSum(100));//累加
        System.out.println(jc(5));//阶乘*/
        //二分查找
        /*  int[] arr = {1,2,3,4,5,6,7,8,9,10};
        int c = 5;
        System.out.println(myBinarySearch(arr, c));
//        注意事项
//        有一个前提条件，数组内的元素一定要按照大小顺序排列，
//        如果没有大小顺序，是不能使用二分查找法的*/
        //冒泡排序
        /* int[] arr = {3,2,5,1,4};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]+" ");
        }*/
        //快速排序
        /*int[] arr = {6, 1, 2, 7, 9, 3, 4, 5, 10, 8};
        quiteSort(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }*/
        //Arrays
        /*int [] arr = {3,2,4,6,7,10,1,8,9,5};
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.binarySearch(arr, 6));
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.binarySearch(arr, 6));*/
    }

    public static int getSum(int i) {
        if (i == 1) {
            return 1;
        } else {
            return i + getSum(i - 1);
        }
    }//累加

    public static int jc(int i) {
        if (i == 1) {
            return 1;
        } else {
            return i * jc(i - 1);
        }
    }//阶乘

    public static int myBinarySearch(int[] arr, int num) {
        int max = arr.length - 1;
        int min = 0;
        while (min <= max) {
            int mid = (min + max) / 2;
            if (arr[mid] > num) {
                max = mid - 1;
            } else if (arr[mid] < num) {
                min = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }//二分查找

    public static void bubbleSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }//冒泡排序

    public static void quiteSort(int[] arr, int start, int end) {
        if (end < start) {
            return;
        }
        int start0 = start;
        int end0 = end;
        int basenum = arr[start0];
        while (end != start) {
            while (arr[end] >= basenum && end > start) {
                end--;
            }
            while (arr[start] <= basenum && end > start) {
                start++;
            }
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }
        int temp = arr[start];
        arr[start] = arr[start0];
        arr[start0] = temp;
        quiteSort(arr, start0, start - 1);
        quiteSort(arr, start + 1, end0);
    }//快速排序
}


class Student {
    private String name;
    private String zi;

    public Student() {
    }

    public Student(String name, String zi) {
        this.name = name;
        this.zi = zi;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getZi() {
        return zi;
    }

    public void setZi(String zi) {
        this.zi = zi;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (zi != student.zi) return false;
        return name != null ? name.equals(student.name) : student.name == null;
    }
/*
    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + age;
        return result;
    }*/

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", zi=" + zi +
                '}';
    }
}
